// store.js
import { createStore } from 'vuex';

const store = createStore({
  state() {
    return {
        messages: [
            {
                orderId: 0,
              content: '达拉斯三马车已通过顺丰速运发出了真维斯重磅卫衣男款秋冬季青少年加绒加厚一体绒美式潮牌男士连帽外套厚',
              time: '2024/12/11 23:41:13',
              trackingNumber: 'SF1539543674561',
              seller: '达拉斯三马车'
            },
            // 其他消息对象...
            {
                orderId: 1,
              content: '那一抹红黑色已通过顺丰速运发出了心相印卷纸纸巾卫生纸厕纸手纸无芯卷筒纸厕所纸家用整箱批发可水溶 4层*70克*10卷',
              time: '2024/12/12 15:20:02',
              trackingNumber: 'SF1234565555553',
              seller: '那一抹红黑色'
            },
            {
                orderId: 2,
              content: 'LA已通过顺丰快递发出了驰界type-c数据线快充线6A正品超级闪充电器120W/100W/88W/66W安卓5A适用华为荣耀小米三星vivo套装',
              time: '2024/12/13 12:05:10',
              trackingNumber: 'SF1395689937176',
              seller: 'LA'
            },
            {
                orderId: 3,
              content: 'KBG已通过京东快递发出了阿司倍鹭（ASVEL）玻璃油壶油瓶不挂油 厨房调味瓶自动开合酱油醋调料瓶 白色650ml',
              time: '2024/12/14 11:00:00',
              trackingNumber: 'JDVC27546805631',
              seller: 'KBG'
            }
          ],
    };
  },
  mutations: {
    DELETE_MESSAGE(state, id) {
     
        console.log('Before:', state.messages); // 查看删除前的 messages
        state.messages = state.messages.filter(message => message.orderId != id);
        console.log('After:', state.messages); // 查看删除后的 messages
    //   state.messages = state.messages.filter(message => message.orderId !== id);
      
    },
    SET_MESSAGES(state, messages) {
      state.messages = messages;
    },
  },
  actions: {
    deleteMessage({ commit }, id) {
      commit('DELETE_MESSAGE', id);
    },
    fetchMessages({ commit }) {
      // Fetch the messages from API or local (if needed)
      const messages = []; // Assume this is your list of messages
      commit('SET_MESSAGES', messages);
    },
  },
  
});

export default store;